package cs275.ants.graph;

import java.util.Iterator;
import java.util.Set;

import cs275.ants.graph.MazeCell.Wall;
import cs275.ants.graph.antgraph.AntGraphVertex;
import cs275.ants.graph.base.Graph;
import cs275.ants.graph.base.GraphVertex;
import junit.framework.TestCase;

public class MazeGeneratorTest extends TestCase {

	private Maze maze;
	private static final int numRow = 3;
	private static final int numCol = 5;
	
	@Override
	protected void setUp() throws Exception {
		MazeGenerator mazeGenerator = new MazeGenerator();
		maze = mazeGenerator.generate(numCol, numRow);
	}
	
	public void testSidesIntact() { 

		int c, r;
		MazeCell[][] cells = maze.getCells();
		
		// top and bottom
		for (c=0; c<numCol; c++) { 
			assertTrue(cells[0][c].hasWall(Wall.UP));
			assertTrue(cells[numRow-1][c].hasWall(Wall.DOWN));
		}
		
		// left and right
		for (r=0; r<numRow; r++) { 
			assertTrue(cells[r][0].hasWall(Wall.LEFT));
			assertTrue(cells[r][numCol-1].hasWall(Wall.RIGHT));
		}
	}
	
	public void testCellsWithFood() { 
		MazeCell[][] cells = maze.getCells();
		cells[2][2].setHasFood(true);		
		
		Graph graph = maze.getGraph(); 
		Set<GraphVertex> set = graph.getAllVertices();
		
		Iterator<GraphVertex> iter = set.iterator(); 
		while (iter.hasNext()) {
			AntGraphVertex v = (AntGraphVertex)iter.next();
			int row = v.getRow(); 
			int col = v.getCol(); 
			if (row == 2 && col == 2) { 
				assertTrue(v.hasFood());
			} else {
				assertFalse(v.hasFood());
			}
		}
	}

}
